#include "dlgtableedit.h"
#include <QDebug>

DlgTableEdit::DlgTableEdit(QWidget *parent) :
    QDialog(parent)
{
    ui.setupUi(this);
}
void DlgTableEdit::setTableName(QString tablename)
{
    model = new QSqlRelationalTableModel(this);
    model->setTable(tablename);
    model->select();
    ui.tableView->setModel(model);
    ui.tableView->setSortingEnabled(true);
}
void DlgTableEdit::on_pushButton_add_clicked()
{
    model->insertRow(0);
}
void DlgTableEdit::on_pushButton_delete_clicked()
{
    QModelIndex  current=this->ui.tableView->currentIndex ();
    int row=current.row();
    model->removeRow(row);
}
void DlgTableEdit::accept()
{
        qDebug("accept");
        model->submitAll();
        QDialog::accept();
}
void DlgTableEdit::reject()
{
        qDebug("reject");
        QDialog::reject();

}
